package com.suixinsanren.design.state.demo.demo01;

import javax.sound.midi.Soundbank;

/**
 * 已出售状态
 */
public class SoldState implements State {

    private GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("稍等，正在给您准备糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("您已经转动曲柄，无法退换硬币");
    }

    @Override
    public void turnCrank() {
        System.out.println("转两圈不会给你带来另一个糖果");
    }

    @Override
    public void dispense() {
        if (gumballMachine.getCount() > 0) {
            gumballMachine.releaseBall();
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("不好意思，糖果买完了");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}
